<template>
	<view class="coupon-page">
		<!-- 页面标题 -->
		<view class="page-header">
			<text class="page-title">领券成功</text>
		</view>
		
		<!-- 成功提示区域 -->
		<view class="success-section">
			<view class="success-icon">
				<text class="icon-text">✓</text>
			</view>
			<view class="success-message">
				<text class="message-title">恭喜您！</text>
				<text class="message-desc">
					购物券已成功领取
					<text class="go-use-link" style="color: #007aff; margin-left: 8rpx;" @click="useCoupon">去使用</text>
				</text>
			</view>
		</view>
		
		<!-- 购物券主体 -->
		<view class="coupon-container">
			<view class="coupon-card">
				<!-- 购物券左侧金额区域 -->
				<view class="coupon-left">
					<view class="amount-section">
						<text class="currency">¥</text>
						<text class="amount">{{couponInfo.money}}</text>
					</view>
				</view>
				
				<!-- 购物券右侧信息区域 -->
				<view class="coupon-right">
					<view class="coupon-validity">
						<text class="validity-text">有效期至：{{couponInfo.end_time}}</text>
					</view>
					<view class="coupon-status" @click="useCoupon">
						<text class="status-text">可使用</text>
					</view>
				</view>
				
				<!-- 购物券装饰元素 -->
				<view class="coupon-decoration">
					<view class="circle circle-left"></view>
					<view class="circle circle-right"></view>
					<view class="dashed-line"></view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				couponId: '', // 购物券ID
				couponInfo: {
					id: '',
					name: '新人专享券',
					amount: 50,
					condition: 100,
					description: '全场通用，无门槛限制',
					validUntil: '2024-12-31',
					status: 'available'
				}
			}
		},
		onLoad(options){
			// 获取传入的购物券ID
			if (options.id) {
				this.couponId = options.id;
				console.log('购物券ID:', this.couponId);
				// 这里后续可以调用API获取购物券详情
				this.getCouponDetail();
			}
		},
		methods: {
			// 获取购物券详情
			getCouponDetail() {
				// TODO: 调用API获取购物券详情
				console.log('获取购物券详情，ID:', this.couponId);
				this.$u.api.user.bindCoupon({coupon_id:this.couponId}).then(res =>{
					if(res.code == 1){
						this.couponInfo = res.data;
						uni.showToast({
							title: res.msg,
							icon: 'success'
						});
					}
				})
			},
			
			// 使用购物券
			useCoupon() {
				uni.showToast({
					title: '正在跳转...',
					icon: 'loading'
				});
				// TODO: 跳转到使用页面或商品页面
				setTimeout(() => {
					uni.switchTab({
						url: '/pages/shop/index'
					});
				}, 1000);
			},
			
			// 返回上一页
			goBack() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
.coupon-page {
	min-height: 100vh;
	background: #ffffff;
	padding: 20rpx;
}

.page-header {
	text-align: center;
	padding: 40rpx 0;
	
	.page-title {
		color: #2c5530;
		font-size: 36rpx;
		font-weight: bold;
	}
}

.success-section {
	text-align: center;
	padding: 60rpx 0;
	
	.success-icon {
		margin-bottom: 30rpx;
		
		.icon-text {
			display: inline-block;
			width: 120rpx;
			height: 120rpx;
			background: linear-gradient(135deg, #4caf50, #2e7d32);
			border-radius: 50%;
			line-height: 120rpx;
			font-size: 60rpx;
			color: #ffffff;
			font-weight: bold;
			box-shadow: 0 10rpx 30rpx rgba(76, 175, 80, 0.3);
		}
	}
	
	.success-message {
		.message-title {
			display: block;
			color: #2c5530;
			font-size: 40rpx;
			font-weight: bold;
			margin-bottom: 15rpx;
		}
		
		.message-desc {
			display: block;
			color: #4a6741;
			font-size: 28rpx;
		}
	}
}

.coupon-container {
	margin: 40rpx 0;
}

.coupon-card {
	background: #fff;
	border-radius: 20rpx;
	box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.1);
	position: relative;
	overflow: hidden;
	display: flex;
	margin: 0 20rpx;
	border: 2rpx solid #e8f5e8;
}

.coupon-left {
	background: linear-gradient(135deg, #ff6b6b, #ee5a24);
	color: #fff;
	padding: 40rpx 30rpx;
	text-align: center;
	position: relative;
	min-width: 200rpx;
	display: flex;
	flex-direction: column;
	justify-content: center;
	align-items: center;
}

.amount-section {
	margin-bottom: 20rpx;
	
	.currency {
		font-size: 32rpx;
		font-weight: bold;
	}
	
	.amount {
		font-size: 60rpx;
		font-weight: bold;
		margin-left: 5rpx;
	}
}

.condition {
	.condition-text {
		font-size: 24rpx;
		opacity: 0.9;
	}
}

.coupon-right {
	flex: 1;
	padding: 40rpx 30rpx;
	position: relative;
	background: #f8fff8;
}

.coupon-validity {
	margin-bottom: 30rpx;
	
	.validity-text {
		font-size: 24rpx;
		color: #4a6741;
	}
}

.coupon-status {
	.status-text {
		background: linear-gradient(135deg, #4caf50, #2e7d32);
		color: #fff;
		padding: 15rpx 30rpx;
		border-radius: 25rpx;
		font-size: 26rpx;
		font-weight: bold;
	}
}

.coupon-decoration {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	pointer-events: none;
}

.circle {
	position: absolute;
	width: 30rpx;
	height: 30rpx;
	background: #f8fff8;
	border-radius: 50%;
	top: 50%;
	transform: translateY(-50%);
}

.circle-left {
	left: -15rpx;
}

.circle-right {
	right: -15rpx;
}

.dashed-line {
	position: absolute;
	left: 0;
	right: 0;
	top: 50%;
	height: 2rpx;
	background: repeating-linear-gradient(
		to right,
		transparent,
		transparent 10rpx,
		#e8f5e8 10rpx,
		#e8f5e8 20rpx
	);
}

.go-use-link{
	font-size: 28rpx;
	color: #4caf50 !important;
}
 

</style>
